﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Xms.Core.Context;
using Xms.CRM.Data;
using Xms.CRM.Domain;
using Xms.Data.Provider;

namespace Xms.CRM
{
    public class StudentCourseRefService : IStudentCourseRefService
    {
        private readonly IStudentCourseRefRepository _iStudentCourseRefRepository;

        public StudentCourseRefService(IStudentCourseRefRepository iStudentCourseRefRepository
            )
        {
            _iStudentCourseRefRepository = iStudentCourseRefRepository;
        }

        public Guid Create(StudentCourseRef entity)
        {
            return _iStudentCourseRefRepository.CreateEntity(entity);
        }

        public bool CreateMany(List<StudentCourseRef> entitys)
        {
            return _iStudentCourseRefRepository.CreateMany(entitys);
        }

        public bool Update(StudentCourseRef entity)
        {
            return _iStudentCourseRefRepository.Update(entity);
        }

        public bool Update(Func<UpdateContext<StudentCourseRef>, UpdateContext<StudentCourseRef>> context)
        {
            var ctx = context(UpdateContextBuilder.Build<StudentCourseRef>());
            return _iStudentCourseRefRepository.Update(ctx);
        }

        public StudentCourseRef FindById(Guid id)
        {
            return _iStudentCourseRefRepository.FindById(id);
        }

        public bool DeleteById(Guid id)
        {
            return _iStudentCourseRefRepository.DeleteById(id);
        }

        public bool DeleteById(List<Guid> ids)
        {
            var flag = true;
            foreach (var id in ids)
            {
                flag = this.DeleteById(id);
            }
            return flag;
            //return _repository.DeleteById(ids);
        }

        public PagedList<StudentCourseRef> QueryPaged(Func<QueryDescriptor<StudentCourseRef>, QueryDescriptor<StudentCourseRef>> container)
        {
            QueryDescriptor<StudentCourseRef> q = container(QueryDescriptorBuilder.Build<StudentCourseRef>());

            return _iStudentCourseRefRepository.QueryPaged(q);
        }

        public List<StudentCourseRef> Query(Func<QueryDescriptor<StudentCourseRef>, QueryDescriptor<StudentCourseRef>> container)
        {
            QueryDescriptor<StudentCourseRef> q = container(QueryDescriptorBuilder.Build<StudentCourseRef>());

            return _iStudentCourseRefRepository.Query(q)?.ToList();
        }

    }
}
